package com.lone.smallmovie.utils.framework;

import java.util.Locale;

import org.springframework.context.ApplicationContext;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author Ant
 * @version 1.0
 */

public class SystemInstance 
{
	
	private static SystemInstance instance = null;

	private ApplicationContext appContext;

	public SystemInstance() {
	}

	/**
	 * @return 返回一个实例.
	 */
	public static SystemInstance getInstance() {
		if (instance == null) 
		{
			instance = new SystemInstance();
		}
		return instance;
	}
    
	public ApplicationContext getAppContext() {
		return appContext;
	}

	public void setAppContext(ApplicationContext appContext) {
		this.appContext = appContext;
	}

	public Object getBean(String beanName) {
		return getAppContext().getBean(beanName);
	}
	/**
	 * get message by specific key
	 * 
	 * @param key
	 * @return
	 */
	public  String getMessage(String key) {
		return appContext.getMessage(key, null, Locale.getDefault());
	}

	/**
	 * get message by specific key
	 * 
	 * @param key
	 * @param args
	 * @return
	 */
	public  String getMessage(String key, Object[] args) {
		return appContext.getMessage(key, args, Locale.getDefault());
	}

	/**
	 * get message by specific key
	 * 
	 * @param key
	 * @param locale
	 * @return
	 */
	public  String getMessage(String key, Locale locale) {
		return appContext.getMessage(key, null, locale);
	}

	/**
	 * get message by specific key
	 * 
	 * @param key
	 * @param args
	 * @param locale
	 * @return
	 */
	public  String getMessage(String key, Object[] args, Locale locale) {
		return appContext.getMessage(key, args, locale);
	}
}